/*
 * HttpServer.cpp
 *
 *  Created on: 2016-7-25
 *      Author: terry
 */

#include "HttpServer.h"
#include "TStringUtil.h"
#include "TStringCast.h"
#include <iostream>
#include <fstream>


bool HttpRequest::get(const char* name, std::string& value)
{
	bool found = false;
	StringMap::const_iterator it = params.find(name);
	if (it != params.end())
	{
		value = it->second;
		found = true;
	}
	else
	{
		char text[1024] = { 0 };
		int ret = mg_get_http_var(&query, name, text, sizeof(text));
		if (ret > 0)
		{
			value = text;
			found = true;
		}
	}
	return found;
}

bool HttpRequest::get(const std::string& name, std::string& value)
{
	bool found = false;
	StringMap::const_iterator it = params.find(name);
	if (it != params.end())
	{
		value = it->second;
		found = true;
	}
	else
	{
		char text[1024] = { 0 };
		int ret = mg_get_http_var(&query, name.c_str(), text, sizeof(text));
		if (ret > 0)
		{
			value = text;
			found = true;
		}
	}
	return found;
}


const char* HttpMethod::GET = "GET";
const char* HttpMethod::POST = "POST";
const char* HttpMethod::PUT = "PUT";
const char* HttpMethod::DELETE = "DELETE";
const char* HttpMethod::OPTION = "OPTION";
